package com.billing.web.controller.common;

public class PowerUtils {
	
	/**
	 * 查看是否具有权限
	 * @param userPurview
	 * @param optPurview
	 * @return
	 */
	 public static Boolean checkPower(Long userPurview, Integer optPurview){   
	   
		 long purviewValue = (long)Math.pow(2, optPurview);   
	     
	     return (userPurview.longValue() & purviewValue) == purviewValue;
	     
	 }   

	 
	 /**
	  * 计算权限值
	  * @param optPurviews
	  * @return
	  */
	 public static long calcPower(Integer... optPurviews){
		 long purview = 0;
		 if(optPurviews != null)
			 for (Integer integer : optPurviews) {
				 purview += (long)Math.pow(2,integer);
			 }
		 return purview;
	 }
	 
	 
	 
	 public static void main(String[] args){
		 
		 //
		 long maxL = 0;
		 for(int i = 0 ; i <6; i++){
			 maxL += (long)Math.pow(2,i);
			 System.out.println(Long.toBinaryString(maxL));
		 }
		 System.out.println(maxL);
		 System.out.println(PowerUtils.checkPower(7L,4));
	 }
}
